home *** CD-ROM | disk | FTP | other *** search
/ The Big Day - Work Smarter - Learn How / The Big Day - Work Smarter - Learn How (Microsoft).BIN / ToolBar.js < prev    next >
Text File  |  2000-12-04  |  18KB  |  617 lines

  1. var ToolBar_Supported = false;
  2. var Frame_Supported   = false;
  3. var DoInstrumentation = false;
  4.  
  5. if (navigator.userAgent.indexOf("MSIE")    != -1 && 
  6. navigator.userAgent.indexOf("Windows") != -1 && 
  7. navigator.appVersion.substring(0,1) > 3)
  8. {
  9. ToolBar_Supported = true;
  10. }
  11.  
  12. if (ToolBar_Supported)
  13. {
  14. var newLineChar = String.fromCharCode(10);
  15. var char34 = String.fromCharCode(34);
  16. var LastMSMenu = "";
  17. var CurICPMenu = "";
  18. var IsMSMenu = false;
  19. var IsMenuDropDown = true;
  20. var HTMLStr;
  21. var x = 0;
  22. var y = 0;
  23. var x2 = 0;
  24. var y2 = 0;
  25. var MSMenuWidth;
  26. var ToolbarMinWidth;
  27. var ToolbarMenu;
  28. var ToolbarBGColor;
  29. var ToolbarLoaded = false;
  30. var aDefMSColor  = new Array(3);
  31. var aDefICPColor = new Array(3);
  32. var aCurMSColor  = new Array(3);
  33. var aCurICPColor = new Array(3);
  34. var MSFont;
  35. var ICPFont;
  36. var MaxMenu = 30;
  37. var TotalMenu = 0;
  38. var arrMenuInfo = new Array(30);
  39.  
  40. // Output style sheet and toolbar ID
  41. document.write("<SPAN ID='StartMenu' STYLE='display:none;'></SPAN>");
  42.  
  43. // Build toolbar template
  44. HTMLStr = 
  45. "<DIV ID='idToolbar'     STYLE='background-color:white;width:100%'>" +
  46. "<DIV ID='idRow1'        STYLE='position:relative;height:20;'>" +
  47. "<DIV ID='idICPBanner'   STYLE='position:absolute;top:0;left:0;height:60;width:250;overflow:hidden;vertical-align:top;'><!--BEG_ICP_BANNER--><!--END_ICP_BANNER--></DIV>" +
  48. "<DIV ID='idMSMenuCurve' STYLE='position:absolute;top:0;left:250;height:20;width:18;overflow:hidden;vertical-align:top;'><IMG SRC='curve.gif' BORDER=0></DIV>" +
  49. "<DIV ID='idMSMenuPane'  STYLE='position:absolute;top:0;left:250;height:20;width:10;background-color:black;float:right;' NOWRAP><!--MS_MENU_TITLES--></DIV>" + 
  50. "</DIV>" +
  51. "<DIV ID='idRow2' STYLE='position:relative;left:250;height:40;'>" +
  52. "<DIV ID='idADSBanner'   STYLE='position:absolute;top:0;left:0;height:40;width:200;vertical-align:top;overflow:hidden;'><!--BEG_ADS_BANNER--><!--END_ADS_BANNER--></DIV>" +
  53. "<DIV ID='idMSCBanner'   STYLE='position:absolute;top:0;left:200;height:40;width:112;vertical-align:top;overflow:hidden;' ALIGN=RIGHT><!--BEG_MSC_BANNER--><!--END_MSC_BANNER--></DIV>" +
  54. "</DIV>" +
  55. "<DIV ID='idRow3' STYLE='position:relative;height:20;width:100%'>" +
  56. "<DIV ID='idICPMenuPane' STYLE='position:absolute;top:0;left:0;height:20;background-color:black;' NOWRAP><!--ICP_MENU_TITLES--></DIV>" +
  57. "</DIV>" +
  58. "</DIV>" +
  59. "<SCRIPT TYPE='text/javascript'>" + 
  60. "   var ToolbarMenu = StartMenu;" + 
  61. "</SCRIPT>" + 
  62. "<DIV WIDTH=100%>";
  63.  
  64. // Define event handlers
  65. window.onresize  = resizeToolbar;
  66.  
  67. // Intialize global variables
  68. ToolbarBGColor= "white";// toolbar background color
  69. MSFont  = "xx-small Verdana";
  70. ICPFont = "bold xx-small Verdana";
  71.  
  72. aDefMSColor[0]= aCurMSColor[0]  = "black";// bgcolor;
  73. aDefMSColor[1]= aCurMSColor[1]  = "white";// text font color
  74. aDefMSColor[2]  = aCurMSColor[2]  = "red";// mouseover font color
  75.  
  76. aDefICPColor[0]= aCurICPColor[0] = "#6699CC";// bgcolor;
  77. aDefICPColor[1] = aCurICPColor[1] = "white";// text font color
  78. aDefICPColor[2] = aCurICPColor[2] = "red";// mouseover font color
  79. }
  80.  
  81. // The hard-coded numbers in functions - drawToolbar() & resizeToolbar()
  82. // correspond to the dimension of the four gif files:
  83. //ICP_BANNER: 60h x 250w
  84. //ADS_BANNER: 40h x 200w
  85. //MSC_BANNER: 40h x 112w
  86. //Curve:    20h x 18w
  87.  
  88. function drawToolbar()
  89. {
  90. HTMLStr += "</DIV>";
  91. document.write(HTMLStr);
  92. ToolbarLoaded = true;
  93.  
  94. MSMenuWidth     = Math.max(idMSMenuPane.offsetWidth, (200+112));
  95. ToolbarMinWidth = (250+18) + MSMenuWidth;
  96.  
  97. idToolbar.style.backgroundColor     = ToolbarBGColor;
  98. idMSMenuPane.style.backgroundColor  = aDefMSColor[0];
  99. idICPMenuPane.style.backgroundColor = aDefICPColor[0];
  100. resizeToolbar();
  101.  
  102. for (i = 0; i < TotalMenu; i++) 
  103. {
  104. thisMenu = document.all(arrMenuInfo[i].IDStr);
  105. if (thisMenu != null)
  106. {
  107. if (arrMenuInfo[i].IDStr == LastMSMenu && arrMenuInfo[i].type == "R")
  108. {
  109. //Last MSMenu has to be absolute width
  110. arrMenuInfo[i].type = "A";
  111. arrMenuInfo[i].unit = 200;
  112. }
  113. if (arrMenuInfo[i].type == "A")
  114. thisMenu.style.width = arrMenuInfo[i].unit;
  115. else 
  116. thisMenu.style.width = Math.round(arrMenuInfo[i].width * arrMenuInfo[i].unit) + 'em';
  117. }
  118. }
  119. }
  120.  
  121. function resizeToolbar()
  122. {
  123. if (ToolBar_Supported == false) return;
  124.  
  125. w = Math.max(ToolbarMinWidth, document.body.clientWidth) - ToolbarMinWidth;
  126.  
  127. idMSMenuCurve.style.left  = (250+w);
  128. idMSMenuPane.style.left   = (250+w+18);
  129. idMSMenuPane.style.width  = MSMenuWidth;
  130.  
  131. idADSBanner.style.left    = (w+18);
  132.  
  133. idMSCBanner.style.left    = (w+18+200);
  134. idMSCBanner.style.width   = (MSMenuWidth - 200);
  135.  
  136. idICPMenuPane.style.width = ToolbarMinWidth + w;
  137. }
  138.  
  139. function setToolbarBGColor(color)
  140. {
  141. ToolbarBGColor = color;
  142. if (ToolbarLoaded == true)
  143. idToolbar.style.backgroundColor = ToolbarBGColor;
  144. }
  145.  
  146. function setMSMenuFont(sFont)
  147. {MSFont = sFont;
  148. }
  149.  
  150. function setICPMenuFont(sFont)
  151. {ICPFont = sFont;
  152. }
  153.  
  154. function setDefaultMSMenuColor(bgColor, fontColor, mouseoverColor)
  155. {
  156. if (bgColor   != "")  aDefMSColor[0] = bgColor;
  157. if (fontColor != "")  aDefMSColor[1] = fontColor;
  158. if (mouseoverColor != "") aDefMSColor[2] = mouseoverColor;
  159. }
  160.  
  161. function setDefaultICPMenuColor(bgColor, fontColor, mouseoverColor)
  162. {
  163. if (bgColor   != "")  aDefICPColor[0] = bgColor;
  164. if (fontColor != "")  aDefICPColor[1] = fontColor;
  165. if (mouseoverColor != "") aDefICPColor[2] = mouseoverColor;
  166. }
  167.  
  168. function setICPMenuColor(MenuIDStr, bgColor, fontColor, mouseoverColor)
  169. {
  170. if (ToolbarLoaded == false) return;
  171.  
  172. // Reset previous ICP Menu color if any
  173. if (CurICPMenu != "")
  174. {
  175. PrevID = CurICPMenu.substring(4);
  176. CurICPMenu = "";
  177. setICPMenuColor(PrevID, aDefICPColor[0], aDefICPColor[1], aDefICPColor[2]);
  178. }
  179.  
  180. varid = "AM_" + "ICP_" + MenuIDStr;
  181. var thisMenu = document.all(id);
  182. if (thisMenu != null)
  183. {
  184. CurICPMenu = "ICP_" + MenuIDStr;
  185. aCurICPColor[0] = bgColor;
  186. aCurICPColor[1] = fontColor;
  187. aCurICPColor[2] = mouseoverColor;
  188.  
  189. // Change menu color
  190. if (bgColor != "")
  191. thisMenu.style.backgroundColor = bgColor;
  192. if (fontColor != "")
  193. thisMenu.style.color = fontColor;
  194.  
  195. // Change subMenu color
  196. id = "ICP_" + MenuIDStr;
  197. thisMenu = document.all(id);
  198. if (thisMenu != null)
  199. {
  200. if (bgColor != "")
  201. thisMenu.style.backgroundColor = bgColor;
  202.  
  203. if (fontColor != "")
  204. {
  205. i = 0;
  206. id = "AS_" + "ICP_" + MenuIDStr;
  207. thisMenu = document.all.item(id,i);
  208. while (thisMenu != null)
  209. {
  210. thisMenu.style.color = fontColor;
  211. i += 1;
  212. thisMenu = document.all.item(id,i);
  213. }
  214. }
  215. }
  216. }
  217. }
  218.  
  219. function setAds(Gif,Url,AltStr)
  220. {setBanner(Gif,Url,AltStr,"<!--BEG_ADS_BANNER-->","<!--END_ADS_BANNER-->");
  221. }
  222.  
  223. function setICPBanner(Gif,Url,AltStr)
  224. {setBanner(Gif,Url,AltStr,"<!--BEG_ICP_BANNER-->","<!--END_ICP_BANNER-->");
  225. }
  226.  
  227. function setMSBanner(Gif,Url,AltStr)
  228. {setBanner(Gif,Url,AltStr,"<!--BEG_MSC_BANNER-->","<!--END_MSC_BANNER-->");
  229. }
  230.  
  231. function setBanner(BanGif, BanUrl, BanAltStr, BanBegTag, BanEndTag)
  232. {
  233. begPos = HTMLStr.indexOf(BanBegTag);
  234. endPos = HTMLStr.indexOf(BanEndTag) + BanEndTag.length;
  235.  
  236. SubStr = HTMLStr.substring(begPos, endPos);
  237. SrcStr = "";
  238. if (BanUrl != "")
  239. SrcStr += "<A Target='_top' HREF='" + formatURL(BanUrl, BanGif) +"'>";
  240. SrcStr += "<IMG SRC='" + BanGif + "' ALT='" + BanAltStr + "' BORDER=0>";
  241. if (BanUrl != "")
  242. SrcStr += "</A>";
  243. SrcStr = BanBegTag + SrcStr + BanEndTag;
  244. HTMLStr = HTMLStr.replace(SubStr, SrcStr);
  245. }
  246.  
  247. function setICPSubMenuWidth(MenuIDStr, WidthType, WidthUnit)
  248. {tempID = "ICP_" + MenuIDStr;
  249. setSubMenuWidth(tempID, WidthType, WidthUnit);
  250. }
  251.  
  252. function setMSSubMenuWidth(MenuIDStr, WidthType, WidthUnit)
  253. {tempID = "MS_" + MenuIDStr;
  254. setSubMenuWidth(tempID, WidthType, WidthUnit);
  255. }
  256.  
  257. function setSubMenuWidth(MenuIDStr, WidthType, WidthUnit)
  258. {
  259. var fFound = false;
  260. if (TotalMenu == MaxMenu)
  261. {
  262. alert("Unable to process menu. Maximum of " + MaxMenu + " reached.");
  263. return;
  264. }
  265.  
  266. for (i = 0; i < TotalMenu; i++)
  267. if (arrMenuInfo[i].IDStr == MenuIDStr)
  268. {
  269. fFound = true;
  270. break;
  271. }
  272.  
  273. if (!fFound)
  274. {
  275. arrMenuInfo[i] = new menuInfo(MenuIDStr);
  276. TotalMenu += 1;
  277. }
  278.  
  279. if (!fFound && WidthType.toUpperCase().indexOf("DEFAULT") != -1)
  280. {
  281. arrMenuInfo[i].type = "A";
  282. arrMenuInfo[i].unit = 160;
  283. }
  284. else
  285. {
  286. arrMenuInfo[i].type = (WidthType.toUpperCase().i